﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Circo.Framework.BusinessLogic.Views.Filters;
using SC.eWedding.BusinessLogic.Views;
using SC.eWedding.BusinessLogic.Handlers;
using System.Text;

public partial class Proveedor_Controles_veInicioSesion : System.Web.UI.UserControl
{
    #region Propiedades Privadas

    private ProveedorView Proveedor
    {
        get { return (ProveedorView)Session["ProveedorView"]; }
        set { Session["ProveedorView"] = value; }
    }

    private string Usuario
    {
        get { return txtUsuario.Text; }
        set { txtUsuario.Text = value; }
    }

    private string Contrasenia
    {
        get { return txtContrasenia.Text; }
        set { txtContrasenia.Text = value; }
    }

    #endregion

    #region Eventos

    protected void btnEntrar_Click(object sender, EventArgs e)
    {
        List<ViewFilter> filtros = new List<ViewFilter>();

        filtros.Add(new ViewCommonFilter("NombreUsuario", Usuario));
        filtros.Add(new ViewCommonFilter("Contrasenia", Contrasenia));

        List<ProveedorView> listProv = ProveedorHandler.FindBy(filtros);
        if (listProv.Count != 0)
        {
            Proveedor = listProv[0];
            Response.Redirect("Producto.aspx");
        }
        else
        {
            if (!Page.ClientScript.IsStartupScriptRegistered("script_Error"))
            {
                StringBuilder script = new StringBuilder();

                script.Append("<script language=\"jscript\">\n");
                script.Append("   alert('Usuario y/o contraseña incorrecto!!');\n");
                script.Append("</script>\n");

                Page.ClientScript.RegisterStartupScript(GetType(), "script_Error", script.ToString());
            }
        }

    }

    #endregion 
}
